package tarena.netctoss.view;

import java.util.List;

import tarena.netctoss.dao.BusinessCondition;
import tarena.netctoss.dao.Pagination;
import tarena.netctoss.dao.UserCondition;
import tarena.netctoss.po.Business;
import tarena.netctoss.po.Pricing;
import tarena.netctoss.po.User;
import tarena.netctoss.service.BusinessService;
import tarena.netctoss.service.PricingService;
import tarena.netctoss.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 用户管理模块控制层
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-3-5
 */
public class UserAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private User user;
	private Business business;
	private BusinessCondition bc;
	private UserService userService;
	private List<User> userList;
	private Pagination page;
	private UserCondition uc;
	private List<Pricing> pricingList;
	private List<Business> businessList;
	private BusinessService businessService;
	private PricingService pricingService;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	/********************** 依赖注入 ***********************/
	/**
	 * 
	 * 
	 * @param userService
	 */
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	/**
	 * 
	 * @param businessService
	 */
	public void setBusinessService(BusinessService businessService) {
		this.businessService = businessService;
	}

	/**
	 * 
	 * @param pricingService
	 */
	public void setPricingService(PricingService pricingService) {
		this.pricingService = pricingService;
	}

	/**************************************************/

	/**
	 * 显示用户管理主页面
	 * 
	 * @return
	 */
	public String index() {
		return SUCCESS;
	}

	/**
	 * 帐务浏览于查询
	 * 
	 * @return
	 */
	public String acctBrowse() {
		// 分页条件
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}

		if (null == uc) {
			uc = new UserCondition();
		}

		userList = userService.findAll(uc, page);
		return SUCCESS;
	}

	/**
	 * 帐务增加表单请求
	 * 
	 * @return
	 */
	public String acctAddForm() {
		return SUCCESS;
	}

	/**
	 * 帐务增加
	 * 
	 * @return
	 */
	public String acctAdd() {
		if (null != user) {
			userService.save(user);
		}
		return SUCCESS;
	}

	/**
	 * 帐务修改列表请求
	 * 
	 * @return
	 */
	public String acctPrepareUpdate() {
		// 分页条件
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		// 查询条件
		if (null == uc) {
			uc = new UserCondition();
		}
		userList = userService.findAll(uc, page);
		return SUCCESS;
	}

	/**
	 * 帐务修表单表请求
	 * 
	 * @return
	 */
	public String acctUpdateForm() {
		if (null != user.getId()) {
			user = userService.findById(user.getId());
		}
		return SUCCESS;
	}

	/**
	 * 帐务修改
	 * 
	 * @return
	 */
	public String acctUpdate() {
		if (null != user) {
			userService.update(user);
		}
		return SUCCESS;
	}

	/**
	 *帐务修改列表请求
	 * 
	 * @return
	 */
	public String acctPrepareDelete() {
		// 分页条件
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		// 查询条件
		if (null == uc) {
			uc = new UserCondition();
		}
		userList = userService.findAll(uc, page);
		return SUCCESS;
	}

	/**
	 * 帐务删除
	 * 
	 * @return
	 */
	public String acctDelete() {
		if (null != user) {
			userService.delete(user);
		}
		return SUCCESS;
	}

	/****************************************************/
	/**
	 * 业务浏览及查询
	 * 
	 * @return
	 */
	public String bussBrowse() {
		// 分页条件
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		if (null == bc) {
			bc = new BusinessCondition();
		}
		businessList = businessService.findAll(bc, page);
		return SUCCESS;
	}

	/**
	 * 业务增加表单请求
	 * 
	 * @return
	 */
	public String bussAddForm() {
		userList = userService.findAll();
		pricingList = pricingService.findAll();
		return SUCCESS;
	}

	/**
	 * 业务增加
	 * 
	 * @return
	 */
	public String bussAdd() {
		if (null != business) {
			businessService.save(business);
		}
		return SUCCESS;
	}

	/**
	 * 业务修改列表请求
	 * 
	 * @return
	 */
	public String bussPrepareUpdate() {
		return SUCCESS;
	}

	/**
	 * 业务修表单表请求
	 * 
	 * @return
	 */
	public String bussUpdateForm() {
		return SUCCESS;
	}

	/**
	 * 业务修改
	 * 
	 * @return
	 */
	public String bussUpdate() {
		return SUCCESS;
	}

	/**
	 * 业务修改列表请求
	 * 
	 * @return
	 */
	public String bussPrepareDelete() {
		return SUCCESS;
	}

	/**
	 *业务删除
	 * 
	 * @return
	 */
	public String bussDelete() {
		return SUCCESS;
	}

	/****************************************************/

	public Business getBusiness() {
		return business;
	}

	public void setBusiness(Business business) {
		this.business = business;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public Pagination getPage() {
		return page;
	}

	public void setPage(Pagination page) {
		this.page = page;
	}

	public UserCondition getUc() {
		return uc;
	}

	public void setUc(UserCondition uc) {
		this.uc = uc;
	}

	public List<Pricing> getPricingList() {
		return pricingList;
	}

	public void setPricingList(List<Pricing> pricingList) {
		this.pricingList = pricingList;
	}

	public BusinessCondition getBc() {
		return bc;
	}

	public void setBc(BusinessCondition bc) {
		this.bc = bc;
	}

	public List<Business> getBusinessList() {
		return businessList;
	}

	public void setBusinessList(List<Business> businessList) {
		this.businessList = businessList;
	}

}
